package offer;

public class offerII_0047 {
    public TreeNode pruneTree(TreeNode root) {
            TreeNode head=new TreeNode(1);
            head.left=root;
            delete(head,root,true);
            return head.left;
    }
    public void delete(TreeNode node1,TreeNode node2,boolean flag){
        if(node2==null) return;
        if(node2.left!=null){
            delete(node2,node2.left,true);
        }
        if(node2.right!=null){
            delete(node2,node2.right,false);
        }
        if(node2.left==null&&node2.right==null&&node2.val==0){
            if(flag) node1.left=null;
            else node1.right=null;
        }
    }
}
